#include "RobotController.h"
#include "RobotModel.h"

void RobotController::Initialization()
{
	pPlayerController = static_cast<PlayerController*>(mWorld->GetController("Player"));

	updateRobotStatus* urs = new updateRobotStatus(this);
	EventTimer* pCurTimer = TimerManager::getSingleton().createTimer(5000,"RobotControlTimer",-1);
	pCurTimer->setCallback(urs);

	Ogre::SceneNode* sn = NULL;
	//Entity* ent = NULL;
	//AnimationState* as = NULL;
	mRobotModels.resize(NUM_MODELS);
    for (unsigned int i = 0; i < NUM_MODELS; i++)
    {
		mRobotModels[i] = new RobotModel(mSceneMgr);
		sn = mRobotModels[i]->getNode();
		sn->yaw(Ogre::Radian(Ogre::Math::TWO_PI * (float)i / (float)NUM_MODELS));
		sn->translate(0, 0, -80, Ogre::Node::TS_LOCAL);

		//mAnimSpeeds.push_back(mRobotModels[i]->AnimSpeed);
		//mAnimStates.push_back(mRobotModels[i]->as);
    }
}

void RobotController::AddTime( Ogre::Real deltatime )
{
    for (unsigned int i = 0; i < NUM_MODELS; i++)
    {
		mRobotModels[i]->setTarget( pPlayerController->getPlayerModel()->getPostion() );
		mRobotModels[i]->AddTime(deltatime);
    }

}

RobotController::RobotController( Ogre::SceneManager *sm ):
	mSceneMgr(sm),NUM_MODELS(6),ANIM_CHOP(1)
{
}

void RobotController::Send( PapaBallMsg msg )
{
	throw std::exception("The method or operation is not implemented.");
}

void RobotModel::setTarget(Ogre::Vector3 t)
{
	target = t;
}